<!--
 * @Author: weisheng
 * @Date: 2024-11-01 11:44:38
 * @LastEditTime: 2024-11-01 14:10:20
 * @LastEditors: weisheng
 * @Description:
 * @FilePath: \wot-demo\src\pages\index.vue
 * 记得注释
-->
<script setup lang="ts"></script>

<template>
  <wd-row>
    <wd-row>
      <wd-col :span="22" :offset="1">
        <view class="bg-dark1">
          <wd-img :width="100" :height="100" :src="bg" />
        </view>
      </wd-col>

      <wd-col :span="22" :offset="1">
        <wd-col :span="12">
          <view class="bg-dark"><wd-img @click="photo" :width="100" :height="100" :src="bg" /></view>
        </wd-col>
        <wd-col :span="12">
          <view class="bg-light"><wd-img @click="uploadPhoto" :width="100" :height="100" :src="bg" /></view>
        </wd-col>
      </wd-col>
    </wd-row>

  </wd-row>


</template>

<style></style>

<route type="home" lang="json">
  {
  "layout": "tabbar",
  "name": "home",
  "style": {
  "navigationBarTitleText": "home"
  }
  }
</route>

<style lang="scss" scoped>
  .bg-dark1 {

    border-radius: 4px;
    min-height: 90px;
    text-align: center;

    line-height: 90px;
    font-size: 12px;
    margin-bottom: 10px;
    // color: rgba(0, 0, 0, 0.45);
  }
</style>

<script>
  export default {

    data() {
      return {

        bg: "../static/logo.png"
      };
    },
    onLoad() {

      this.InquiriesEmpower();

    },

    mounted() {

    },
    methods: {
      // 授权问询
      InquiriesEmpower() {
        console.log(12312312)
        uni.showModal({
          // title: '提示',
          content: '获取授权失败，是否重新授权？',
          success: function(res) {
            if (res.confirm) {
              console.log('用户点击确定');
              uni.openSetting({
                success(res) {
                  console.log(res.authSetting)
                }
              });
            } else if (res.cancel) {
              console.log('用户点击取消');
              uni.navigateBack()
            }
          }
        });

      },
      photo() {
        console.log("+++++")
        uni.chooseImage({
          sizeType: ['original', 'compressed'],
          sourceType: ['camera'],
          success: function(res) {
            this.submitFlag = false
            uni.showLoading()
            uni.uploadFile({
              url: '上传地址',
              filePath: res.tempFilePaths[0],
              name: 'file',
              formData: {
                file: res
              },
              header: {
                'Authorization': uni
                  .getStorageSync('token'),
              },
              success: (res) => {
                console.log('相机上传', res);
                if (res.statusCode == 200) {
                  const data = JSON.parse(res.data)
                  _this.fileList.push({
                    url: `${'前缀'}/${data.data}`
                  })
                  _this.submitFlag = true
                  uni.hideLoading()
                }
              },
              fail: (err) => {
                console.error(err);
              }
            });
          }
        });


      },

      uploadPhoto() {
        uni.chooseImage({
          count: 6, //默认9
          sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
          sourceType: ['album'], //从相册选择
          success: function(res) {
            console.log(JSON.stringify(res.tempFilePaths));

          }
        });
      }

    }
  };
</script>
